package com.ruoyi.wecom.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.dto.admin.wecom.WecomTagGroupAddDTO;
import com.ruoyi.business.domain.dto.admin.wecom.WecomTagGroupDelDTO;
import com.ruoyi.business.domain.dto.admin.wecom.WecomTagGroupEditDTO;
import com.ruoyi.business.domain.vo.wecom.admin.TbWecomTagGroupVO;
import com.ruoyi.business.service.wecom.ITbWecomTagGroupService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Validated
@Api(value = "企微标签组管理", tags = {"企微标签组管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/wecom/tag/group")
public class WecomTagGroupController extends BaseController {

    @Resource
    private ITbWecomTagGroupService tbWecomTagGroupService;

    /**
     * 企微标签组与标签
     */
    @ApiOperation("管理台查询企微标签组与标签")
    @SaCheckPermission("wecom:tag:group:list")
    @GetMapping("/sys-list")
    public R<List<TbWecomTagGroupVO>> list(@ApiParam("标签或标签组名称") @RequestParam(required = false) String name) {
        return R.ok(tbWecomTagGroupService.queryTagList(name));
    }

    /**
     * 新增企微标签组标签
     */
    @ApiOperation("新增企微标签组标签")
    @SaCheckPermission("wecom:tag:group:add")
    @PostMapping("/sys-add")
    public R<Boolean> add(@Validated @RequestBody WecomTagGroupAddDTO wecomTagGroupAddDTO) {
        return R.ok(tbWecomTagGroupService.addTagGroup(wecomTagGroupAddDTO));
    }

    /**
     * 修改企微标签组标签
     */
    @ApiOperation("修改企微标签组标签")
    @SaCheckPermission("wecom:tag:group:edit")
    @PostMapping("/sys-edit")
    public R<Boolean> edit(@Validated @RequestBody WecomTagGroupEditDTO wecomTagGroupEditDTO) {
        return R.ok(tbWecomTagGroupService.editTagGroup(wecomTagGroupEditDTO));
    }

    /**
     * 删除标签或标签组
     */
    @ApiOperation("修改企微标签组标签")
    @SaCheckPermission("wecom:tag:group:del")
    @PostMapping("/sys-del")
    public R<Boolean> del(@Validated @RequestBody WecomTagGroupDelDTO wecomTagGroupDelDTO) {
        return R.ok(tbWecomTagGroupService.delTagGroup(wecomTagGroupDelDTO));
    }

    /**
     * 同步企微标签与标签组
     */
    @ApiOperation("同步企微标签组标签")
    @SaCheckPermission("wecom:tag:group:sync")
    @PostMapping("/sys-sync")
    public R<Boolean> sysSyncWecomData() {
        return R.ok(tbWecomTagGroupService.sysSyncWecomTagData());
    }


}
